<template>
  <page-header-wrapper :title="false">
    <a-card title="导出数据管理">
      <template slot="extra">
        <a-button icon="export" type="primary" @click="doExport">导出</a-button>
      </template>
      <div class="table-page-search-wrapper">
        <a-form-model
          layout="inline"
          :model="queryParam"
        >
          <a-row :gutter="15">
            <a-col :md="6" :sm="24">
              <a-form-model-item label="顾问类型">
                <a-select v-model="queryParam['filter[group_type]']" placeholder="选择查询顾问的类型">
                  <a-select-option v-for="(item,index) in groupTypeOpts" :key="index" :value="index">{{item}}</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-model-item label="审核时间">
                <a-range-picker @change="onTime" />
              </a-form-model-item>
            </a-col>
            <a-col :md="8" :sm="24">
                <span class='table-page-search-submitButtons'>
                  <a-button type="primary" @click="$refs.table.refresh(true)">搜索</a-button>
                </span>
            </a-col>
          </a-row>
        </a-form-model>
      </div>
      <div class="table-operator">
        <s-table
          bordered
          ref="table"
          :row-key="(record) => record.payment_id"
          :columns="paymentColumns"
          :data="paymentData"
        >
        </s-table>
      </div>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import storage from 'store'
import { ACCESS_TOKEN, COMPANY } from '@/store/mutation-types'
import { STable } from '@/components'
import exportColumns from '@/columns/export'
import { getExportList } from '@/api/export'
import apis from '@/api'

export default {
  components: {
    STable
  },
  name: 'Export',
  data () {
    return {
      paymentColumns: exportColumns.payment,
      paymentData: parameters => {
        return getExportList(Object.assign(parameters, this.queryParam)).then(res => {
          this.groupTypeOpts = res.result.group_type
          return res.result
        })
      },
      queryParam: {},
      groupTypeOpts: {},
      exportUrl: process.env.VUE_APP_API_BASE_URL + apis.Export,
      accessToken: storage.get(ACCESS_TOKEN),
      company: storage.get(COMPANY)
    }
  },
  methods: {
    onTime (data, dataString) {
      this.queryParam['filter[check_time_start]'] = dataString[0]
      this.queryParam['filter[check_time_end]'] = dataString[1]
    },
    doExport () {
      const url =
        this.exportUrl + '?access_token=' + this.accessToken +
        '&company=' + this.company +
        '&filter[group_type]=' + this.queryParam['filter[group_type]'] +
        '&filter[check_time_start]=' + this.queryParam['filter[check_time_start]'] +
        '&filter[check_time_end]=' + this.queryParam['filter[check_time_end]']
        window.open(url)
    }
  }
}
</script>

<style scoped>

</style>
